﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using GameEngine;

namespace Daphne.Forms
{
    /// <summary>
    /// Interaction logic for NewGameForm.xaml
    /// </summary>
    public partial class NewGameForm : Window
    {
        private GameSettings _newGS = new GameSettings();

        public NewGameForm()
        {
            InitializeComponent();

            uxOnePlayerGame.Checked += new RoutedEventHandler(_uxOnePlayerGame_Checked);
            uxTwoPlayerGame.Checked += new RoutedEventHandler(_uxTwoPlayerGame_Checked);
            uxPlayGame.Click += new RoutedEventHandler(btnNewGame_Click);
            uxCancel.Click += new RoutedEventHandler(btnCancel_Click);

            //uxCzech.IsChecked = true;
            uxLevel1.IsChecked = true;
            uxComputerBlack.IsChecked = true;
            uxOnePlayerGame.IsChecked = true;
        }

        void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        void btnNewGame_Click(object sender, RoutedEventArgs e)
        {
            RecordNewGameSettings();
            this.DialogResult = true;
            this.Close();
        }

        void _uxTwoPlayerGame_Checked(object sender, RoutedEventArgs e)
        {
            EnableComputerSelection(false);
        }

        void _uxOnePlayerGame_Checked(object sender, RoutedEventArgs e)
        {
            EnableComputerSelection(true);
        }

        public GameSettings NewGameSettings
        {
            get
            {
                return _newGS;
            }
        }

        private void RecordNewGameSettings()
        {
            //if (uxCzech.IsChecked == true)
            //    _newGS.GameType = enumGameType.Czech;
            //else if (uxEnglish.IsChecked == true)
            //    _newGS.GameType = enumGameType.English;
            //else if (uxInternational.IsChecked == true)
            //    _newGS.GameType = enumGameType.International;

            _newGS.GameType = enumGameType.Czech;

            _newGS.OnePlayerGame = uxOnePlayerGame.IsChecked == true ? true : false;
            _newGS.ComputerPlaysWhite = uxComputerWhite.IsChecked == true ? true : false;

            if (uxLevel1.IsChecked == true)
                _newGS.ComputerLevel = 1;
            else if (uxLevel2.IsChecked == true)
                _newGS.ComputerLevel = 2;
            else if (uxLevel3.IsChecked == true)
                _newGS.ComputerLevel = 3;
            else if (uxLevel4.IsChecked == true)
                _newGS.ComputerLevel = 4;
            else if (uxLevel5.IsChecked == true)
                _newGS.ComputerLevel = 5;    
        }

        private void EnableComputerSelection(bool bEnable)
        {
            uxComputerWhite.IsEnabled = bEnable;
            uxComputerBlack.IsEnabled = bEnable;
            uxLevel1.IsEnabled = bEnable;
            uxLevel2.IsEnabled = bEnable;
            uxLevel3.IsEnabled = bEnable;
            uxLevel4.IsEnabled = bEnable;
            uxLevel5.IsEnabled = bEnable;
        }
    }
}
